export const RiskAssessmentPie = () => {
  // There should not be negative values in rawData
  const rawData = [
    { city: "百色市", red: "4", orange: "7", yellow: "0", blue: "2" },
    { city: "河池市", red: "2", orange: "0", yellow: "0", blue: "0" },
    { city: "南宁市", red: "0", orange: "3", yellow: "2", blue: "2" },
    { city: "西林市", red: "0", orange: "5", yellow: "0", blue: "2" },
    { city: "桂林市", red: "2", orange: "0", yellow: "0", blue: "2" }
  ];
  const colors = ["#fe2727", "#f9a016", "#eff704", "#53d5ff"]
  const alar = ["红色风险", "橙色风险", "黄色风险", "蓝色风险"]
  const rawDataSum = []
  rawDataSum.push(rawData.map(obj => { return obj.red }))
  rawDataSum.push(rawData.map(obj => { return obj.orange }))
  rawDataSum.push(rawData.map(obj => { return obj.yellow }))
  rawDataSum.push(rawData.map(obj => { return obj.blue }))
  const grid = {
    left: 50,
    right: 5,
    top: 50,
    bottom: 50
  };

  const seriesArrayFunction = () => {
    const series = rawDataSum.map((name, sid) => {
      return {
        name: alar[sid],
        type: 'bar',
        stack: 'total',
        barWidth: '25%',
        label: {
          show: true,
          formatter: (params) => params.value == 0 ? '' : params.value
        },
        itemStyle: {
          normal: { color: colors[sid] }
        },
        data: rawDataSum[sid]
      };
    });
    return series;
  }



  return {
    legend: {
      selectedMode: true,
      textStyle: {
        color: '#fff'                              // 图例文字颜色
      }
    },
    grid,
    tooltip: {
      show: true

    },
    yAxis: {
      type: 'value',
      splitLine: {
        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
          color: '#222',
          width: 1,
          type: 'solid'
        }
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#eee'
        }
      },
    },
    xAxis: {
      type: 'category',
      data: rawData.map(obj => { return obj.city }),
      axisLabel: {
        show: true,
        textStyle: {
          color: '#eee'
        }
      },
    },
    series: seriesArrayFunction()
  };
}


